library(dplyr)
library(ggplot2)
# Dados
df <- tibble::tibble(
Authors   = c("WANG Y","WANG X","LI Y","ZHANG Y","LIU J","LI X","LIU Y","CHEN X","WANG H","ZHANG J"),
Documents = c(157,116,110,107,99,92,91,85,84,83)
)
# Ordenando
df <- df %>% arrange(Documents)
p <- ggplot(df, aes(x = Documents, y = factor(Authors, levels = df$Authors))) +
geom_segment(aes(x = 0, xend = Documents, yend = factor(Authors, levels = df$Authors)),
linewidth = 0.4) +
geom_point(aes(size = Documents)) +
geom_text(aes(label = Documents), vjust = 0.5, hjust = 0.5, size = 3) +
labs(x = "N. of Documents", y = "Authors") +
theme_minimal(base_size = 12)
p
p <- ggplot(df, aes(x = Documents, y = factor(Authors, levels = df$Authors))) +
geom_segment(aes(x = 0, xend = Documents, yend = factor(Authors, levels = df$Authors)),
linewidth = 0.4) +
geom_point(
aes(size = Documents),
shape = 21,                   # bolinha com preenchimento e contorno
fill  = "#A6DCE3",            # cor mais clara (simula ~50% da turquesa)
color = "#2CA3B9",            # contorno
stroke = 0.3
) +
geom_text(aes(label = Documents), vjust = 0.5, hjust = 0.5, size = 3) +
labs(x = "N. of Documents", y = "Authors") +
theme_minimal(base_size = 12)
p
setwd("C://Users//gabri//Desktop//base de dados artigo revisão//Figuras")
# === 2) Leitura dos dados ===
# A planilha deve conter as colunas: Year, Articles
df <- read_xlsx("Figura_1/Base_de_dados_figura_1.xlsx", sheet = 1)
if(!all(c("Year","Articles") %in% names(df))){
stop("As colunas exigidas (Year, Articles) não foram encontradas.")
}
df
# Código Figura 1
library(readxl)
library(dplyr)
library(ggplot2)
if(!all(c("Year","Articles") %in% names(df))){
stop("As colunas exigidas (Year, Articles) não foram encontradas.")
}
df <- df %>% arrange(Year)
# Código Figura 1
library(readxl)
library(dplyr)
library(ggplot2)
setwd("C://Users//gabri//Desktop//base de dados artigo revisão//Figuras")
# === 2) Leitura dos dados ===
# A planilha deve conter as colunas: Year, Articles
df <- read_xlsx("Figura_1/Base_de_dados_figura_1.xlsx", sheet = 1)
if(!all(c("Year","Articles") %in% names(df))){
stop("As colunas exigidas (Year, Articles) não foram encontradas.")
}
df <- df %>% arrange(Year)
# === 3) Gráfico no estilo Biblioshiny com ggplot2 ===
p <- ggplot(df, aes(x = Year, y = Articles)) +
geom_line(color = "black", linewidth = 0.6) +
labs(title = "Annual Scientific Production",
x = "Year", y = "Articles") +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(size = 14, face = "bold", hjust = 0.5, margin = margin(b = 10)),
panel.grid.minor = element_line(size = 0.2, colour = "grey85"),
panel.grid.major = element_line(size = 0.3, colour = "grey85")
)
# Visualizar (opcional):
print(p)
skim(df$Articles)
skimr::skim(df$Articles)
setwd("C://Users//gabri//Desktop//base de dados artigo revisão//Figuras")
output_eps <- "Most_Relevant_Sources_300dpi.eps"
library(readxl)
library(dplyr)
library(ggplot2)
# ===== 2) Leitura e preparo =====
df <- read_xlsx("Figura_2/Base_figura_2.xlsx", sheet = 1)
# A planilha traz os nomes 'Sources' e 'Articles' na primeira linha de dados.
# Forçamos os nomes das colunas e removemos a primeira linha.
names(df)[1:2] <- c("Sources","Articles")
df <- df[-1, ]
df <- df %>%
mutate(Articles = suppressWarnings(as.numeric(Articles))) %>%
filter(!is.na(Articles), !is.na(Sources))
# Top 10
top <- df %>% arrange(desc(Articles)) %>% slice(1:10)
# Inverter ordem para desenhar de baixo p/ cima
top <- top %>% arrange(Articles)
# ===== 3) Gráfico (ggplot2 base) =====
p <- ggplot(top, aes(x = Articles, y = factor(Sources, levels = top$Sources))) +
geom_segment(aes(x = 0, xend = Articles, y = factor(Sources, levels = top$Sources),
yend = factor(Sources, levels = top$Sources)), linewidth = 0.4) +
geom_point(aes(size = Articles)) +
geom_text(aes(label = Articles), vjust = 0.5, hjust = 0.5, size = 3) +
labs(title = "Most Relevant Sources",
x = "N. of Documents", y = "Sources") +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(size = 14, face = "bold", hjust = 0.5, margin = margin(b = 8))
) +
scale_size(range = c(3, 15), guide = "none")
p
# ===== 3) Gráfico (ggplot2 base) =====
p <- ggplot(top, aes(x = Articles, y = factor(Sources, levels = top$Sources))) +
geom_segment(aes(x = 0, xend = Articles, y = factor(Sources, levels = top$Sources),
yend = factor(Sources, levels = top$Sources)), linewidth = 0.4) +
geom_point(
aes(size = Articles),
shape = 21,
fill  = "#A6DCE3",
color = "#2CA3B9",
stroke = 0.3
)  +
geom_text(aes(label = Articles), vjust = 0.5, hjust = 0.5, size = 3) +
labs(title = "Most Relevant Sources",
x = "N. of Documents", y = "Sources") +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(size = 14, face = "bold", hjust = 0.5, margin = margin(b = 8))
) +
scale_size(range = c(3, 15), guide = "none")
p
# Figure 4 code
library(readxl)
library(dplyr)
library(tidyr)
library(ggplot2)
# ==== Parameters ====
setwd("C://Users//gabri//Desktop//base de dados artigo revisão//Figuras")
output_eps <- "Most_Relevant_Countries_SCP_MCP_300dpi.eps"
top_n      <- 20   # number of countries to show (sorted by total)
# ==== Read ====
df_raw <- read_xlsx("Figura_4/Base_figura_4.xlsx", sheet = 1)
View(df_raw)
# The first row in the sheet repeats the headers. Normalize names and drop that row.
# We rename the first five columns to ensure consistent names even if they are "Unnamed".
nm <- names(df_raw)
if (length(nm) < 5) stop("Sheet does not have expected columns.")
names(df_raw)[1:5] <- c("Country","Articles","ArticlesPerc","SCP","MCP")
df <- df_raw %>%
filter(!is.na(Country)) %>%
filter(Country != "Country") %>%
mutate(
Articles = suppressWarnings(as.numeric(Articles)),
SCP      = suppressWarnings(as.numeric(SCP)),
MCP      = suppressWarnings(as.numeric(MCP))
) %>%
filter(!is.na(SCP), !is.na(MCP)) %>%
mutate(Total = SCP + MCP) %>%
arrange(desc(Total)) %>%
slice_head(n = top_n)
# ==== Long format for stacking ====
df_long <- df %>%
select(Country, SCP, MCP) %>%
pivot_longer(cols = c(SCP, MCP), names_to = "Type", values_to = "Count")
# ==== Plot ====
p <- ggplot(df_long, aes(x = Count, y = reorder(Country, sum(Count)), fill = Type)) +
geom_col(position = "stack") +
labs(x = "N. of Documents", y = "Countries") +
theme_minimal(base_size = 12) +
theme(
panel.grid.major.y = element_blank(),
plot.margin = margin(10, 15, 10, 10)
)
# ==== Save EPS (300 dpi) ====
# On Windows/macOS, ggplot2 uses cairo_ps if available for EPS.
ggsave(filename = output_eps, plot = p, device = cairo_ps,
width = 10, height = 6, units = "in", dpi = 300)
p
df_raw = df_raw[-1,]
View(df_raw)
View(df_raw)
# ==== Parameters ====
setwd("C://Users//gabri//Desktop//base de dados artigo revisão//Figuras")
output_eps <- "Most_Relevant_Countries_SCP_MCP_300dpi.eps"
top_n      <- 20   # number of countries to show (sorted by total)
# ==== Parameters ====
setwd("C://Users//gabri//Desktop//base de dados artigo revisão//Figuras")
# Figure 4 code
library(readxl)
library(dplyr)
library(tidyr)
library(ggplot2)
# ==== Parameters ====
setwd("C://Users//gabri//Desktop//base de dados artigo revisão//Figuras")
output_eps <- "Most_Relevant_Countries_SCP_MCP_300dpi.eps"
top_n      <- 20   # number of countries to show (sorted by total)
# ==== Read ====
df_raw <- read_xlsx("Figura_4/Base_figura_4.xlsx", sheet = 1)
df_raw = df_raw[-1,]
View(df_raw)
# Figure 4 code
library(readxl)
library(dplyr)
library(tidyr)
library(ggplot2)
# ==== Parameters ====
setwd("C://Users//gabri//Desktop//base de dados artigo revisão//Figuras")
output_eps <- "Most_Relevant_Countries_SCP_MCP_300dpi.eps"
top_n      <- 20   # number of countries to show (sorted by total)
# ==== Read ====
df_raw <- read_xlsx("Figura_4/Base_figura_4.xlsx", sheet = 1)
View(df_raw)
nm <- names(df_raw)
if (length(nm) < 5) stop("Sheet does not have expected columns.")
names(df_raw)[1:5] <- c("Country","Articles","ArticlesPerc","SCP","MCP")
df <- df_raw %>%
filter(!is.na(Country)) %>%
filter(Country != "Country") %>%
mutate(
Articles = suppressWarnings(as.numeric(Articles)),
SCP      = suppressWarnings(as.numeric(SCP)),
MCP      = suppressWarnings(as.numeric(MCP))
) %>%
filter(!is.na(SCP), !is.na(MCP)) %>%
mutate(Total = SCP + MCP) %>%
arrange(desc(Total)) %>%
slice_head(n = top_n)
# ==== Long format for stacking ====
df_long <- df %>%
select(Country, SCP, MCP) %>%
pivot_longer(cols = c(SCP, MCP), names_to = "Type", values_to = "Count")
# ==== Plot ====
p <- ggplot(df_long, aes(x = Count, y = reorder(Country, sum(Count)), fill = Type)) +
geom_col(position = "stack") +
labs(x = "N. of Documents", y = "Countries") +
theme_minimal(base_size = 12) +
theme(
panel.grid.major.y = element_blank(),
plot.margin = margin(10, 15, 10, 10)
)
p
View(df_raw)
str(df_long)
df_long = as.data.frame(df_long)
# ==== Plot ====
p <- ggplot(df_long, aes(x = Count, y = reorder(Country, sum(Count)), fill = Type)) +
geom_col(position = "stack") +
labs(x = "N. of Documents", y = "Countries") +
theme_minimal(base_size = 12) +
theme(
panel.grid.major.y = element_blank(),
plot.margin = margin(10, 15, 10, 10)
)
p
# ==== Plot ====
p <- ggplot(df_long,
aes(x = Count,
y = reorder(Country, Count, FUN = sum),  # <-- aqui
fill = Type)) +
geom_col(position = "stack") +
labs(x = "N. of Documents", y = "Countries") +
theme_minimal(base_size = 12) +
theme(panel.grid.major.y = element_blank())
p
?biblioshinny
